<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        table {
            width: 500px;
            border: 1px solid black;
            border-collapse: collapse;
        }

        th, td {
            border: 1px solid black;
        }
    </style>
</head>
<body>
<h2>学生信息表</h2>
<table>
    <thead>
    <tr>
        <th>ID</th>
        <th>姓名</th>
        <th>年龄</th>
        <th>分数</th>
    </tr>
    </thead>
    <tbody>

    </tbody>
</table>


<script>
    // 学生新表中的数据 后续可以通过ajax请求获取  用户列表    记录
    var students = [
        {
            id: 1,
            name: 'admin',
            age: 20,
            score: 78
        },
        {
            id: 2,
            name: 'super',
            age: 22,
            score: 78
        },
    ]

    var tbd = document.getElementsByTagName('tbody')[0]
    // 追加tr
    students.forEach(student => {
        // 创建行节点
        var tr = document.createElement('tr')
        // 遍历对象属性
        for (var attr in student) {
            // 创建单元格对象
            var td = document.createElement('td')
            td.innerText = student[attr]
            tr.appendChild(td)
        }
        // 追加tr
        tbd.appendChild(tr)
    })

</script>

</body>
</html>